package demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("login")
public class LoginController {
    //登录
    @RequestMapping("userLogin")
    public String login(HttpServletRequest request,HttpServletResponse response){
        String name=request.getParameter("name");
        String password=request.getParameter("password");
        if("zhangsan".equals(name)&&
        "123".equals(password)){
            User user=new User(name,password);
            request.getSession().setAttribute("user",user);
            return "center";
        }
        return "index";
    }
    @RequiredUser
    @RequestMapping("getString")
    @ResponseBody
    public String getString(){
        return "test";
    }
    //登出
    @RequiredUser
    @RequestMapping("logOut")
    public String logOut(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return "index";
    }

}
